package com.tiamo.chatgpt.rest;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tiamo.chatgpt.domain.chatKey.ChatKeyDto;
import com.tiamo.chatgpt.service.ChatKeyService;
import com.tiamo.common.web.controller.BaseController;
import com.tiamo.common.web.response.WebResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author luozhiwei
 * @date 2023/6/3 下午6:50
 */
@RestController
@Api(tags = "消息key")
@RequestMapping("/chatKey")
public class ChatKeyController implements BaseController {

    @Resource
    private ChatKeyService chatKeyService;

    @ApiOperation("分页")
    @GetMapping("/page")
    public WebResponse<Page<ChatKeyDto>> page(@ApiParam("页数") @RequestParam(required = false, defaultValue = "1") Integer page,
                                              @ApiParam("条数") @RequestParam(required = false, defaultValue = "10") Integer size,
                                              @ApiParam("状态 0启用1关闭2过期") @RequestParam(required = false) Integer status) {
        Page<ChatKeyDto> resultPage = chatKeyService.pageByParam(page, size, status);
        return ok(resultPage);
    }

    @ApiOperation("新增")
    @PostMapping("/add")
    public WebResponse<Page<ChatKeyDto>> add(@RequestBody ChatKeyDto dto) {
        Boolean add = chatKeyService.add(dto);
        return add ? ok() : defaultErr();
    }
}
